/**
 * 适用表格类的联调，跳转
 * @param emit 通知事件方法
 * @returns triggerInteraction 方法
 */
export const useInteraction = (emit: any, extra = {} as any) => {
  const { xAxisName } = extra;
  // 时间选择器组件增加时间格式类型subType
  const triggerInteraction = ({
    seriesType,
    interactionState,
    values,
    index,
    name,
    subType,
  }: any) => {
    const { isLinkage, isJump, isDrilled } = interactionState;
    // Todo: 下钻
    isDrilled && triggerDrillData({ seriesType, values, index, name, subType });
    // 触发联动
    isLinkage && triggerLinkage({ seriesType, values, index, name, subType });
    // 触发跳转
    isJump && triggerJump({ seriesType, values, index, name });
  };
  // 联动处理
  const triggerLinkage = ({ seriesType, values, index, name, subType }: any) => {
    emit('relationSetChange', { seriesType, values, index, name, subType });
  };
  // 取消联动信息
  const closureLinkage = () => {
    // 更新图表高亮信息
    emit('cancelRelationSet');
  };

  // 下钻处理
  const triggerDrillData = ({ seriesType, values, index, name, subType }: any) => {
    const params = {
      seriesType,
      values,
      index,
      name,
      subType,
      drillType: 'scrollBoard',
      mapComponent: [],
      xAxisName,
    };
    emit('drillChange', params);
  };

  // 触发上钻
  const triggerDrillUp = ({ index, item }) => {
    emit('drillUp', { index, item });
  };

  // 触发跳转信息
  const triggerJump = ({ seriesType, values, index, name }: any) => {
    emit('jumpChange', { seriesType, values, index, name });
  };

  return {
    triggerInteraction,
    triggerDrillUp,
    closureLinkage,
  };
};
